﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Supersense.users;

public partial class admin_users_update : System.Web.UI.Page
{
    public Users user = new Users();

    protected void Page_Load(object sender, EventArgs e)
    {
        username.Text = Session["username"].ToString().Trim(); 
    }

    protected void ok_Click(object sender, EventArgs e)
    {
        string oldpasswd = this.oldpasswd.Text;
        string newpasswd = this.newpasswd.Text;
        string confirmpasswd = this.confirmpasswd.Text;

        DataTable dt = user.get_user(Session["username"].ToString().Trim());
        if (dt != null)
        {
            if (dt.Rows[0]["password"].ToString().Trim() != oldpasswd)
            {
                Response.Write("<script type='text/javascript'>alert('原密码不正确!');history.go(-1);</script>");
            }
            if (newpasswd != confirmpasswd)
            {
                Response.Write("<script type='text/javascript'>alert('新密码和确认密码不一致!');history.go(-1);</script>");
            }
            if (user.update_user(Session["username"].ToString().Trim(), newpasswd, dt.Rows[0]["name"].ToString().Trim()))
            {
                Response.Write("<script type='text/javascript'>alert('您执行的操作成功了!')</script>");
                Response.Write("<meta http-equiv='refresh' content='0;url=update.aspx'/>");
            }
            else
            {
                Response.Write("<script type='text/javascript'>alert('您执行的操作失败了!');history.go(-1);</script>");
            }
        }
        else
        {
            Response.Write("<script type='text/javascript'>alert('该用户不存在!');history.go(-1);</script>");
        }
    }
}
